//# 战斗相关脚本
using UnityEngine;

public class Projectile : MonoBehaviour
{
    public float speed = 20f;
    public float damage = 20f;
    public float lifetime = 2f;
    private Vector2 direction;

    public void Initialize(Vector2 dir, float damage)
    {
        direction = dir;
        this.damage = damage; // 设置投射物的伤害
        Destroy(gameObject, lifetime);
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Enemy"))
        {
            other.GetComponent<BaseCharacter>()?.TakeDamage(damage);
            Destroy(gameObject);
        }
        else if (other.CompareTag("Player"))
        {
            // 处理投射物与玩家的碰撞
            Debug.Log("Projectile hit the player!");
            Destroy(gameObject);
        }
    }
}